﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T07_Interface
{
    class Program
    {
        static void Main(string[] args)
        {
            BankCard card1 = new BankCard("张三");
            CreditCard card2 = new CreditCard("李四");
            IPay[] pays = { card1, card2,new BankCard("王五") { Money = 150 } };
            foreach (IPay pay in pays)
            {
                if (pay.Pay(200))
                {
                    Console.WriteLine("{0}付款成功", pay.GetName());
                }
                else
                {
                    Console.WriteLine("{0}付款失败", pay.GetName());
                }
            }
        }
    }
    /// <summary>
    /// Ixxxx形式表示是接口 xxxable也是表示接口
    /// </summary>
    interface IPay
    {
        bool Pay(decimal price);
        string GetName();
    }
    /// <summary>
    /// 借记卡类
    /// </summary>
    class BankCard : IPay
    {
        //属性
        private string name;

        public BankCard(string name)
        {
            this.name = name;
        }
        //字段
        public decimal Money = 1000;

        //生成相关代码：Alt+Enter

        public string GetName()
        {
            return name;
        }

        public bool Pay(decimal price)
        {
            if(Money>=price )
            {
                Money -= price;
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    /// <summary>
    /// 信用卡
    /// </summary>
    class CreditCard : IPay
    {
        private string name;

        public CreditCard(string name)
        {
            this.name = name;
        }
        public decimal Overdraft = 0;
        public string GetName()
        {
            return this.name;
        }
        public bool Pay(decimal price)
        {
            Overdraft += price;
            return true;
        }
    }
}
